<%@codepage="65001"%>
<%session.codepage="65001"%>

<!-- #include virtual=/inc/dbConn.asp -->
<!--METADATA TYPE= "typelib" NAME= "ADODB Type Library" FILE="C:\Program Files\Common Files\SYSTEM\ADO\msado15.dll" -->
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Pragma" content="no-cache">	  
<%
	Response.CharSet = "utf-8" 
	Response.AddHeader "Pragma","no-cache"
	Response.AddHeader "Expires","0"

	If Request.Cookies("S_uid") = "" Then 
		response.write "Session Off!!"
		response.end
	End If 

	Function GoogleSendMailer(strTo, strFrom, strSubject, strBody)
		On Error Resume Next
		Set iMsg = CreateObject("CDO.Message")
		Set iConf = CreateObject("CDO.Configuration")
		Set Flds = iConf.Fields
		schema = "http://schemas.microsoft.com/cdo/configuration/"
		Flds.Item(schema & "sendusing") = 2
		Flds.Item(schema & "smtpaccountname") = strFrom '"Jade <hooshim@gmail.com>"
		Flds.Item(schema & "sendmailaddress") = strFrom '"Jade <hooshim@gmail.com>"
		Flds.Item(schema & "smtpuserreplymailaddress") = strFrom '"Jade <hooshim@gmail.com>"
		Flds.Item(schema & "smtpserver") = "smtp.gmail.com"
		Flds.Item(schema & "smtpserverport") = 465
		Flds.Item(schema & "smtpauthenticate") = 1
		Flds.Item(schema & "sendusername") = "hooshim@gmail.com"
		Flds.Item(schema & "sendpassword") = "jj101010"		
		Flds.Item(schema & "smtpusessl") = 1
		Flds.Update
		Set Flds = Nothing
		Set iMsg = Server.CreateObject("CDO.Message")
		With iMsg
			.Configuration = iConf
			.To = strTo
			.From = strFrom
			.Subject = strSubject
			.HTMLBody = strBody
			SendEmailGmail = .Send
		End With
		Set iMsg = Nothing
		Set iConf = Nothing
		Set Flds = Nothing
		If Err.number <> 0 Then
			GoogleSendMail = Err.Description
		Else
			GoogleSendMail = 0
		End If 
	End Function 
	
	Function aFieldValue(Q)		' 한개의 필드의 값을 구하는 함수
		Set Rsf=Server.CreateObject("ADODB.RecordSet")
		Rsf.open Q, dbCon
		if Rsf.eof or Rsf.bof then
			aFieldValue = ""
		Else
			aFieldValue = Rsf(0)				
		End If
	End Function	

	Set upload = server.CreateObject("DEXT.FileUpload")
	Set fs = CreateObject("Scripting.FileSystemObject")
	upload.DefaultPath = server.MapPath("/files/")
	upload.CodePage = 65001

	If IsObject(upload) = False Then
		response.write("DEXTUpload가 생성이 되지 않았습니다.")
		response.End
	End If
	subjects = Replace(upload("subjects"),"'","''")
	context = Replace(upload("context"),"'","''")
	context = Replace(context,"</P>" & vbcrlf & "<P>","<br>")
'	Response.write "<META http-equiv='Content-Type' content='text/html; charset=utf-8'>"
'	Response.write Len(context) & "////" & context

	sender = upload("sender")
	rcvr = upload("rcvr")
	endDt = upload("endDt")
	tmpFlag = upload("tmpFlag")
	workSeq = upload("workSeq")
	isFile = upload("isFile")
	'toEmail = upload("toEmail")
	If workSeq = "" Then 
		workSeq = 0
	End if 
	If tmpFlag = "" Then 
		tmpFlag = "-"
	End If 
	If part = "" Then 
		part = "0"
	End If 
	fileNm = upload("uFile").FileName  
	If fileNm = "" And isFile <> "" Then 
		fileNm = isFile
	End If 
	
	flag = "Y"
		
	'response.end
	If mode = "del" Then 
	Else '쓰기 or 수정
		
		files = upload("uFile").FileName  
		If files <> "" Then 
			files = upload("uFile").Save( ,false)
		End If 
		
		Set Cmd  = Server.CreateObject("ADODB.Command")
		With Cmd
			.ActiveConnection = DbCon
			.CommandText = "dbo.spSaveWorkBbs"  
			.CommandType = adCmdStoredProc
			.Parameters.Append .CreateParameter("@writeId", adVarchar,adParamInput, 200) 
			.Parameters.Append .CreateParameter("@subjects", adVarchar,adParamInput, 200) 
			.Parameters.Append .CreateParameter("@rcvrs", adVarchar,adParamInput, 200) 
			'.Parameters.Append .CreateParameter("@contents", adVarChar,adParamInput, 8000)adLongVarChar, adParamInput, LenB(content), content) 
			.Parameters.Append .CreateParameter("@contents", adLongVarChar, adParamInput, LenB(context),contents) 
			.Parameters.Append .CreateParameter("@files", adVarchar,adParamInput, 200) 

			.Parameters.Append .CreateParameter("@endDt", adVarchar,adParamInput, 200) 
			.Parameters.Append .CreateParameter("@workSeq", adInteger,adParamInput, 3) 
			.Parameters.Append .CreateParameter("@part", adVarchar,adParamInput, 200)
			.Parameters.Append .CreateParameter("@flag", adVarchar,adParamInput, 200)
			.Parameters.Append .CreateParameter("@tmpFlag", adVarchar,adParamInput, 200)

			.Parameters("@writeId").Value = sender
			.Parameters("@subjects").Value = subjects
			.Parameters("@rcvrs").Value = rcvr
			.Parameters("@contents").Value = context
			.Parameters("@files").Value = fileNm
			.Parameters("@endDt").Value = endDt
			.Parameters("@workSeq").Value = workSeq
			.Parameters("@part").Value = part
			.Parameters("@flag").Value = flag
			.Parameters("@tmpFlag").Value = tmpFlag

			Set Rs= .Execute
		End With

		Set Cmd = Nothing

		'## toEmail 이 있는 경우 ############
		'If toEmail <> "" Then 
		'	Call GoogleSendMailer(toEmail, "Intranet 발신전용 <hooshim@gmail.com>", "[Intranet] " & subjects, context)
		'End If 

		'## 메일 발송용 문서 작성 ############
		'mailContext = "<B>마감일 : " & endDt & "</B><BR><BR>자세한 내용은 Intranet에서 확인 바랍니다.<BR><BR><a href=""http://intra.antiochcenter.org"" target=""_blank"">[인트라넷 바로가기]</a>"
		Response.write "<script>alert('저장되었습니다.');self.close();</script>"
		'Response.redirect("/groupWorkWrite.asp")
		Response.End
	End If 
%>
<%session.codepage="949"%>
